/**
 * Created by Eoly on 2017/1/1.
 */
function ArcEffects() {
    this.r = 1;
    this.max_r = 100;
    this.risingIndex = 1;
    this.bombIndex = 1.01;
    this.point = new Point();
    this.fillColor = new Color(0, 0, 0, 0.8);
    this.strokeColor = new Color(255, 100, 100, 0.8);
    this.isEnd = false;
    this.count = 0;
}

ArcEffects.prototype = {

    setIndexByMaxR: function () {
        this.bombIndex = Math.pow(this.max_r, 0.005);
        // console.log(this.bombIndex);
    },

    effects: function () {
        if (!this.count) {
            this.setIndexByMaxR();
        }
        this.count++;
        if (this.r >= this.max_r) {
            this.fillColor.a = this.fillColor.a * 0.99 - 0.01;
            this.strokeColor.a = this.strokeColor.a * 0.99 - 0.01;
            this.r *= this.bombIndex;
            if (this.fillColor.a <= 0.01) {
                this.isEnd = true;
            }
        } else {
            this.r *= this.risingIndex;
        }
    },

    draw: function (ctx) {
        this.effects();
        ctx.beginPath();
        ctx.arc(this.point.x, this.point.y, this.r, 0, Math.PI * 2);
        ctx.fillStyle = this.fillColor.getRGBA();
        ctx.strokeStyle = this.strokeColor.getRGBA();
        ctx.fill();
        ctx.stroke();
    }
};

function loadTrackEffects(track, color, painter) {
    color = color || '#fff';
    var trackStep = track.trackStep.bind(track);
    track.trackStep = function () {
        this.oldCentrePoint = {};
        this.oldCentrePoint.x = this.centrePoint.x;
        this.oldCentrePoint.y = this.centrePoint.y;
        trackStep();
        painter.lineCap = painter.lineJoin = "round";
        painter.lineWidth = 1;
        painter.strokeStyle = color;
        painter.fillStyle = color;
        painter.moveTo(this.oldCentrePoint.x, this.oldCentrePoint.y);
        painter.lineTo(this.centrePoint.x, this.centrePoint.y);
        painter.stroke();
    }
}